package com.weactivity.controller;

import com.weactivity.dto.*;
import com.weactivity.entity.Resource;
import com.weactivity.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resource")
public class ResourceController {

    @Autowired
    ResourceService resourceService;

    //分页展示资源
    @PostMapping("/showByPage")
    public Result queryResource(PageQueryDTO pageQueryDTO){
        PageResult pageResult = resourceService.pageQuery(pageQueryDTO);
        return Result.ok(pageResult);

    }

    //创建资源
    @PostMapping("/new")
    public Result newResource(@RequestBody ResourceDTO resourceDTO){
        resourceService.newResource(resourceDTO);
        return Result.ok();
    }



    //资源预订
    @PostMapping("/reserve")
    public Result reserve(@RequestBody ReserveDTO reserveDTO){
        resourceService.reserve(reserveDTO);
        return Result.ok();
    }

    //取消预订
    @PostMapping("/{id}")
    public Result cancel(@PathVariable("id")Integer id){
        resourceService.updateById(id);
        return Result.ok();
    }

}
